package com.wei.duowan.bbs.ui.activity;

import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.wei.duowan.bbs.App;
import com.wei.duowan.bbs.R;
import com.wei.duowan.bbs.presenter.BasePresenter;
import com.wei.duowan.bbs.ui.adapter.BaseRecyclerViewAdapter;
import com.wei.duowan.bbs.ui.adapter.BaseViewHolder;

import java.util.Arrays;

import butterknife.Bind;

/**
 * 作者：赵若位
 * 时间：2019/10/17 10:53
 * 联系方式：1070138445
 * 功能：
 */
public class SettingActivity extends BaseActivity
{
    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private BaseRecyclerViewAdapter mAdapter;


    @Override
    protected BasePresenter createPresenter()
    {
        return null;
    }

    @Override
    protected int getLayoutID()
    {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView()
    {
        setTitle(R.string.setting);
        setFinish();
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new BaseRecyclerViewAdapter<String>(this, R.layout.layout_setting)
        {
            @Override
            protected void convert(int position, @Nullable BaseViewHolder holder, @Nullable String s)
            {
                View line = holder.setText(R.id.tv_title, s)
                        .setText(R.id.tv_descript, position == 3 ? "2.49MB" : (position == 4 ? "3.2.4" : ""))
                        .setVisibility(R.id.tv_descript, position == 3 || position == 4 ? View.VISIBLE : View.GONE)
                        .setVisibility(R.id.img_more, position == 3 ? View.GONE : View.VISIBLE)
                        .setVisibility(R.id.tv_line_, position == 0 ? View.VISIBLE : View.GONE)
                        .setVisibility(R.id.tv_line, position == 0 ? View.GONE : View.VISIBLE)
                        .setOnClickListener(R.id.tv_title, view -> SettingActivity.this.onClick(position))
                        .getView(R.id.tv_line);
                ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) line.getLayoutParams();
                params.setMargins(position % 2 == 0 ? App.getResource().getDimensionPixelOffset(R.dimen.dp_12) : 0, 0, 0, 0);
                line.setLayoutParams(params);
            }
        };

        mAdapter.bindRecyclerView(mRecyclerView);
        mAdapter.setNewData(Arrays.asList(new String[]
                {
                        "绑定账号",
                        "正文字号",
                        "消息提醒",
                        "清楚缓存",
                        "版本信息",
                        "关于"
                }));
    }


    /*列表点击事件*/
    private void onClick(int position)
    {
        switch (position)
        {
            case 0://绑定账号
                openActivity(BindAccountActivity.class);
                break;
            case 1://正文字号
                openActivity(FontSizeActivity.class);
                break;
            case 2://消息提醒:
                openActivity(RemindMsgActivity.class);
                break;
            case 3://清楚缓存
                break;
            case 4://版本信息
                break;
            case 5://关于:
                openActivity(AboutActivity.class);
                break;
        }
    }

}
